package com.ruoyi.message.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.message.domain.GroupUserId;
import com.ruoyi.message.service.IGroupUserIdService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 群成员Controller
 * 
 * @author ruoyi
 * @date 2023-10-19
 */
@RestController
@RequestMapping("/groupUser")
public class GroupUserIdController extends BaseController
{
    @Autowired
    private IGroupUserIdService groupUserIdService;

    /**
     * 查询群成员列表
     */
    @RequiresPermissions("message:groupUser:list")
    @GetMapping("/list/{groupId}")
    public TableDataInfo list(@PathVariable("groupId") String groupId)
    {
        System.out.println(groupId);
        GroupUserId groupUserId1 = new GroupUserId();
        groupUserId1.setGroupId(Long.valueOf(groupId));
        List<GroupUserId> list = groupUserIdService.selectGroupUserIdList(groupUserId1);
        return getDataTable(list);
    }

    /**
     * 导出群成员列表
     */
    @RequiresPermissions("message:groupUser:export")
    @Log(title = "群成员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GroupUserId groupUserId)
    {
        List<GroupUserId> list = groupUserIdService.selectGroupUserIdList(groupUserId);
        ExcelUtil<GroupUserId> util = new ExcelUtil<GroupUserId>(GroupUserId.class);
        util.exportExcel(response, list, "群成员数据");
    }

    /**
     * 获取群成员详细信息
     */
    @RequiresPermissions("message:groupUser:query")
    @GetMapping(value = "/{groupId}")
    public AjaxResult getInfo(@PathVariable("groupId") Long groupId)
    {
        return success(groupUserIdService.selectGroupUserIdByGroupId(groupId));
    }

    /**
     * 新增群成员
     */
    @RequiresPermissions("message:groupUser:add")
    @Log(title = "群成员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GroupUserId groupUserId)
    {
        return toAjax(groupUserIdService.insertGroupUserId(groupUserId));
    }

    /**
     * 修改群成员
     */
    @RequiresPermissions("message:groupUser:edit")
    @Log(title = "群成员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GroupUserId groupUserId)
    {
        return toAjax(groupUserIdService.updateGroupUserId(groupUserId));
    }

    /**
     * 删除群成员
     */
    @RequiresPermissions("message:groupUser:remove")
    @Log(title = "群成员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{groupIds}")
    public AjaxResult remove(@PathVariable Long[] groupIds)
    {
        return toAjax(groupUserIdService.deleteGroupUserIdByGroupIds(groupIds));
    }
}
